package dp;

import java.util.Arrays;
import java.util.Scanner;

public class 跳跃_动态规划版本 {

    //可以走的方向
    public static int next[][] = {
            {0, 1}, {1, 0},
            {0, 2}, {2, 0},
            {0, 3}, {3, 0},
            {1, 1}, {1, 2},
            {2, 1}
    };
    static int n;
    static int m;
    static int sum = -0x3f3f3f3f;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        m = scanner.nextInt();

        int[][] map = new int[n + 1][m + 1];
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                map[i][j] = scanner.nextInt();
            }
        }

        for (int i = n; i >= 1; i--) {
            for (int j = m; j >= 1; j--) {
                if (i == n && j == m) continue;
                int maxTemp = -0x3f3f3f3f;
                for (int k = 0; k < 9; k++) {
                    int tx = i + next[k][0];
                    int ty = j + next[k][1];
                    if (tx > n || ty > m) continue;
                    maxTemp = Math.max(map[tx][ty], maxTemp);
                }
                print(map);
                map[i][j] += maxTemp;
            }
        }

        System.out.println(map[1][1]);

    }


    private static void print(int[][] map) {
        System.out.println("====");
        for (int[] line : map) {
            System.out.println(Arrays.toString(line));
        }
        System.out.println("====");
    }

}
